/**

   file.h
   ======

   File management header

**/


#ifndef FILE_H
#define FILE_H


/**

   Includes
   --------

   - stdint.h    :  uintX_t 
   - ptread.h    :  pthread_mutex_t
   - uuid.h      :  uuid needed
   - bitfield.h  :  struct bitfield
   - chunk.h     :  struct chunk
   - huffman.h   :  struct huff_tree

**/

#include <stdint.h>
#include <pthread.h>
#include <bitfield.h>
#include "chunk.h"
#include "huffman.h"



/**

   Structure: struct file
   ----------------------

   A file: Members are
   - name    :  Filename as a bitfield (for prefix code compression) 
   - lock    :  Lock for chunks mutations
   - nchunks :  Number of chunks  
   - offset  :  Offset in last chunk
   - chunks  :  chunks list

**/


struct file
{
  struct bitfield* name;
  pthread_mutex_t lock;
  uint64_t nchunks;
  uint32_t offset;
  struct chunk* chunks;
};


/**

   Prototypes
   ----------

**/

struct file* file_create(char* name, struct huff_tree* t);
struct chunk* file_add_chunk(struct file* f);
void file_delete(struct file* f);
int file_compare(struct file* f1, struct file* f2);


#endif
